package a_o2odata_deal.utils.zhibo_qy

import a_aa_amainpackage.a_o2odata_deal.config.config.{months, years}
import a_aa_amainpackage.a_o2odata_deal.utils.tm_toes
import com.alibaba.fastjson.JSON
import org.apache.spark.sql.SQLContext
import org.apache.spark.{SparkConf, SparkContext}
import org.elasticsearch.spark._

/**
  * @ Auther: o2o-rd-0008
  * @ Date:   2020/2/11 16:59
  * @ Param:  ${PARAM}
  * @ Description: 
  */
object to_es {
  def main(args: Array[String]): Unit = {
    val conf = new SparkConf()
    conf.setAppName(s"${this.getClass.getSimpleName}")
    conf.set("spark.debug.maxToStringFields", "500")
    conf.setMaster("local[*]")
    conf.set("es.nodes", "192.168.1.157")
    conf.set("es.port", "9200")
    conf.set("cluster.name", "O2OElastic")
    conf.set("spark.serializer", "org.apache.spark.serializer.KryoSerializer")
    conf.set("spark.sql.caseSensitive", "true")
    val sc = new SparkContext(conf)
    val sqlContext = new SQLContext(sc)
    sc.setLogLevel("WARN")
    sc.hadoopConfiguration.set("fs.s3a.access.key", "GAO7EO9FWKPJ8WFCQDME")
    sc.hadoopConfiguration.set("fs.s3a.secret.key", "LZ0xaHBSYKHaJ9ECDbX9f7zin79UZkXfGoNapRPL")
    sc.hadoopConfiguration.set("fs.s3a.endpoint", "https://obs.cn-north-1.myhuaweicloud.com")

    //天猫详情数据入库
    tm_toes.restart(sc,sqlContext)

    //所有主播数据入库
    sqlContext.read.orc(s"s3a://o2o-dataproces-group/panzonghao/tmall/${years}/${months}/all_anchor")
      .toJSON.rdd.map(line =>{
      JSON.parseObject(line)
    }).saveToEs(s"${years}_all_anchor/all_anchor_${years}_${months}", Map("es.mapping.id" -> "anchorId"))

    //天猫主播及其商品数据数据入库
    sqlContext.read.orc(s"s3a://o2o-dataproces-group/panzonghao/tmall/${years}/${months}/zhibo_zhubo")
      .toJSON.rdd.map(line =>{
      JSON.parseObject(line)
    }).saveToEs(s"${years}_tmall_anchor/tmall_anchor_${years}_${months}", Map("es.mapping.id" -> "anchorId"))

    sqlContext.read.orc(s"s3a://o2o-dataproces-group/panzonghao/tmall/${years}/${months}/zhibo_live_good").toJSON.rdd.map(line =>{
      JSON.parseObject(line)
    }).saveToEs(s"${years}_tmall_good_live/tmall_good_live_${years}_${months}", Map("es.mapping.id" -> "liveAndgood_id"))

    //天猫主播及其商品数据数据入库
    sqlContext.read.orc(s"s3a://o2o-dataproces-group/panzonghao/taobao/${years}/${months}/zhibo_zhubo").toJSON.rdd.map(line =>{
      JSON.parseObject(line)
    }).saveToEs(s"${years}_taobao_anchor/taobao_anchor_${years}_${months}", Map("es.mapping.id" -> "anchorId"))

    sqlContext.read.orc(s"s3a://o2o-dataproces-group/panzonghao/taobao/${years}/${months}/zhibo_live_good").toJSON.rdd.map(line =>{
      JSON.parseObject(line)
    }).saveToEs(s"${years}_taobao_good_live/taobao_good_live_${years}_${months}", Map("es.mapping.id" -> "liveAndgood_id"))

    //主播店铺数据入库
    sqlContext.read.orc(s"s3a://o2o-dataproces-group/panzonghao/tmall/${years}/${months}/anchor_shop").toJSON.rdd.map(line =>{
      JSON.parseObject(line)
    }).saveToEs(s"anchor_shop/anchor_shop", Map("es.mapping.id" -> "major_key"))


  }

}
